package cn.com.nes.common.wx.pay;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class PayTest {
	   public static void main(String[] args) {
			String orderNo = "45696119648920220628";
			String weixinOpenId = "oQVcL4-3qDQL4lDpfK1tyhZqL7LY";//oQVcL47Qj55fT0ObtRKcIJoCu3ZQ
			String realname = "无玉兴";
			//转账的金额  金额格式转换可以参考 https://www.cnblogs.com/pxblog/p/13186037.html
			Double payAmount = 1.00;
			String desc = "企业付款备注";
			
			File pkcFile = new File(System.getProperty("catalina.home")+File.separator+"apiclient_cert.p12") ;
			
			Object result[] = WeixinPay.payToUser(pkcFile, orderNo, weixinOpenId, realname, payAmount, desc,"127.0.0.1");
			String resXml = (String) result[1];
			boolean postError = (Boolean) result[0];
			if (!postError) {
				Map<String, String> map = new HashMap<String, String>();
				try {
					map = PayUtil.parseXMLToMap(resXml);
				} catch (Exception e) {
					e.printStackTrace();
				}
				String returnCode = map.get("return_code");
				if (returnCode.equalsIgnoreCase("FAIL")) {
					//支付失败
					System.err.println( map.get("return_msg"));
				} else if (returnCode.equalsIgnoreCase("SUCCESS")) {
					if (map.get("err_code") != null) {
						//支付失败
						System.err.println( map.get("err_code_des"));
					} else if (map.get("result_code").equalsIgnoreCase(
						"SUCCESS")) {
						//支付成功  paymentNo：微信付款单号  payment_time：付款成功时间
						String paymentNo = map.get("payment_no");
						String payment_time = map.get("payment_time");
						try {
							//如果是体现操作，在这里处理体现订单的状态，把状态转为提现成功

						} catch (Exception e) {
							e.printStackTrace();
						}
						System.err.println("返回到成功的页面");
					}
				}
			}
			System.err.println("返回通信失败的错误页面");
		}
}
